<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                {if $model['app_id'] == ''}
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">绑定微信小程序</div>
                </div>
				<div class="widget-body am-cf" style="padding-bottom: 20px;">
					<div style="background:#eeeeee;margin-left:100px;border-radius:10px;padding:20px;" class="am-u-sm-6 am-u-md-6 am-u-lg-3">
						<div style="text-align:center;font-weight: 900;">我已有微信小程序</div>
						<div style="margin-top:20px;text-align:center;">
							<a class="am-btn am-btn-default am-btn-success am-radius" href="{$url}">
                                扫码绑定
                            </a>
						</div>
						<div style="margin-top:20px;text-align:center;color:#999;">
						    <small>
						        {$model['template']['value'] == 0?'授权需取消“小程序开发与数据分析”权限':'授权时不要取消任何一项权限集'}
						    </small>
						</div>
					</div>
					{if $model['template']['value'] == 0}
					<div style="background:#eeeeee;margin-left:100px;border-radius:10px;padding:20px;" class="am-u-sm-6 am-u-md-6 am-u-lg-3">
						<div style="text-align:center;font-weight: 900;">我已有微信小程序</div>
						<div style="margin-top:20px;text-align:center;">
							<span class="hema-init am-btn am-btn-default am-btn-success am-radius">
                                手动设置
                            </span>
						</div>
						<div style="margin-top:20px;text-align:center;color:#999;">
						    <small>手动配置小程序参数</small>
						</div>
					</div>
					{/if}
					<div style="background:#eeeeee;margin-left:100px;border-radius:10px;padding:20px;" class="am-u-sm-6 am-u-md-6 am-u-lg-3">
						<div style="text-align:center;font-weight: 900;">
                        {if !$apply}
                            我还没有微信小程序
                        {else /}
                            {if $apply['pay_status']['value']==10}
                                现在状态：<code>待付审核费</code>
                            {else /}
                                现在状态：<code>{$apply['apply_status']['text']}</code>
                            {/if}
                        {/if}
						</div>
						<div style="margin-top:20px;text-align:center;">
							<a class="am-btn am-btn-default am-btn-success am-radius" href="{:url('wxapp.register/wxapp')}">
                                {$apply ? '查看详情':'快速注册'}
                            </a>
						</div>
						<div style="margin-top:20px;text-align:center;color:#999;">
						    <small>快速注册并认证小程序</small>
						</div>
					</div>
					<div style="" class="am-u-sm-6 am-u-md-6 am-u-lg-3"></div>
				</div>
				{else /}
				<form id="my-app" class="am-form tpl-form-line-form" method="post">
					<div class="widget-head am-cf">
                        <div class="widget-title am-fl">微信小程序设置</div>
                    </div>
                    <!--授权模式-->
                    {if $model['status']['value'] == 1}
                    <div class="tips am-margin-bottom-sm am-u-sm-12">
                        {if $model['app_type'] == ''}
                        <div class="pre-error">
                            自定义模板为线下发布小程序，授权项必须取消“小程序开发与数据分析”权限，否则无法进行线下发布小程序
                        </div>
                        {else /}
                        <div class="pre-error">
                            在线发布小程序前必须完成初始化配置。配置项目 1.小程序头像 2.小程序名称 3.功能介绍 4.服务器域名 5.服务类目 6.隐私设置
                        </div>
                        {/if}
                    </div>
                    <div class="widget-body am-cf">
                        <fieldset>
						<div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label">同步公众平台设置 </label>
                            <div class="am-u-sm-9 am-u-end">
								<div class="am-btn-group am-btn-group-xs">
									<a href="javascript:;" class="item-synchronization am-btn am-btn-default am-btn-secondary am-radius" data-id="{$model['app_id']}">
										<span class="am-icon-refresh am-icon-sm"></span> 一键同步
									</a>
								</div>
                            </div>
                        </div>
						<div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label">小程序头像 </label>
                            <div class="am-u-sm-9 am-u-end">
                                <img style="border-radius: 50%;" src="{$model['head_img']}" width="72" height="72" alt="微信小程序头像">
								<div class="help-block am-margin-top-sm">
                                    <small>
                                    {if isset($infor['head_image_info'])}
                                    每月可修改{$infor['head_image_info']['modify_quota']}次，
                                    本月还可修改{$infor['head_image_info']['modify_quota']-$infor['head_image_info']['modify_used_count']}次。
                                    {/if}
                                        <a href="javascript:void(0);" class="hema-set-head">修改</a>
                                    </small>
                                </div>
                            </div>
                        </div>
						<div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label">小程序名称 </label>
                            <div class="am-u-sm-9 am-u-end">
                                <input type="text" class="tpl-form-input" value="{$model['app_name']}" disabled="disabled">
								<small>友情提醒：名称设置后不可修改<a href="{:url('wxapp.name/setting')}">设置</a></small>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label">
                                AppId <span class="tpl-form-line-small-title">小程序Id</span>
                            </label>
                            <div class="am-u-sm-9 am-u-end">
                                <input type="text" class="tpl-form-input" value="{$model['app_id']}" disabled="disabled">
                            </div>
                        </div>
						<div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">小程序介绍 </label>
                            <div class="am-u-sm-9 am-u-end">
                                <input type="text" class="tpl-form-input" name="data[signature]" value="{$model['signature']}" required>
									<small>
                                    {if isset($infor['signature_info'])}
										每月可修改{$infor['signature_info']['modify_quota']}次，
										本月还可修改{$infor['signature_info']['modify_quota']-$infor['signature_info']['modify_used_count']}次。
									{/if}
									</small>									
                            </div>
                        </div>
						<div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">服务器域名 </label>
                            <div class="am-u-sm-9 am-u-end">
								<input type="text" class="tpl-form-input" name="data[api_domain]" value="{$model['api_domain']}" required>
								<small>
									请确保上面域名列表至少有一个在下方域名列表中，多个以“;”隔开，否则无法正常使用小程序。<br>
									最新域名列表：{$model['serve_domain']}
								</small>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label">业务域名 </label>
                            <div class="am-u-sm-9 am-u-end">
								<input type="text" class="tpl-form-input" name="data[webview_domain]" value="{$model['webview_domain']}">
								<small>
									非必须设置项，多个以“;”分号隔开，设置格式如：www.baidu.com。<br>
									域名前面不要加“https://”协议头，后面不要加“/”斜杠
								</small>
                            </div>
                        </div>
                        </fieldset>
                    </div>
                    {else /}
                    <div class="widget-body am-cf">
                        <fieldset>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">小程序 <span class="tpl-form-line-small-title">头像</span></label>
                            <div class="am-u-sm-9 am-u-end">
                                <div class="am-form-file">
                                     <button type="button" class="upload-file am-btn am-btn-secondary am-radius am-btn-sm">
                                        <i class="am-icon-cloud-upload" style="color:#fff"></i>选择图片
                                    </button>
                                    <div class="uploader-list am-cf">
                                        <div class="file-item">
                                            <a href="{$model['head_img']}" title="点击查看大图" target="_blank">
                                                <img src="{$model['head_img']}">
                                            </a>
                                            <input type="hidden" name="data[head_img]"
                                                   value="{$model['head_img']}">
                                        </div>
                                    </div>
                                </div>
                                <div class="help-block am-margin-top-sm">
                                    <small>建议尺寸200*200px，大小2M以下</small>
                                </div>
                            </div>
                        </div>
						<div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">小程序 <span class="tpl-form-line-small-title">名称</span> </label>
                            <div class="am-u-sm-9 am-u-end">
                                <input type="text" class="tpl-form-input" name="data[app_name]" value="{$model['app_name']}" required>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">
                                AppId <span class="tpl-form-line-small-title">小程序Id</span>
                            </label>
                            <div class="am-u-sm-9 am-u-end">
                                <input type="text" class="tpl-form-input" name="data[app_id]" value="{$model['app_id']}" required>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">
                                App_Secret <span class="tpl-form-line-small-title">小程序秘钥</span>
                            </label>
                            <div class="am-u-sm-9 am-u-end">
                                <input type="text" class="tpl-form-input" name="data[app_secret]" value="{$model['app_secret']}" required>
                            </div>
                        </div>
                        </fieldset>
                    </div>
					{/if}
					<div class="widget-body am-cf">
    					<div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
                {/if}
            </div>

        </div>

    </div>

</div>
<!-- 图片文件列表模板 -->
{include file="../addons/upload/view/template/tpl_file_item_url.html" /}
<!-- 文件库弹窗 -->
{include file="../addons/upload/view/template/file_library.html" /}
{include file="wxapp/init" /}
{include file="wxapp/sethead" /}
<script>

    $(function () {
        //修改头像
        $('.hema-set-head').on('click', function () {
            var data = $(this).data();
            $.get("{:url('wxapp/sethead')}", function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
				$.showAction({
                    title: '小程序头像设置', 
                    area: '750px', 
                    content: template('tpl-set-head', {model:result.data.model}), 
                    uCheck: true, 
                    success: function ($content) {
                        // 选择图片
                        $('.upload-file-set-head').selectImages({
                            name: 'data[head_img]'
                        });
                        $('#my-form').formPost({
                            url: "{:url('wxapp/sethead')}"
                        });
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
         //添加
        $('.hema-init').on('click', function () {
            $.showAction({
                title: '添加', 
                area: '750px', 
                content: template('tpl-init', {}), 
                uCheck: true, 
                success: function ($content) {
                    $('#my-form').formPost({
                        url: "{:url('wxapp/index')}"
                    });
                }, 
                btn2: function ($content) {
                    return true;
                }
            });
        });
        // 选择图片
        $('.upload-file').selectImages({
            name: 'data[head_img]'
        });
		// 同步设置
        var url = "{:url('wxapp/synchronization')}";
        $('.item-synchronization').del('app_id', url,'确定要同步吗？');
        $('#my-app').formPost();
    });

</script>

